﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Micua.iChat.Models;

namespace ChatServer.Hubs
{
    [HubName("DataHub")]
    public class DataHub : Hub
    {
        public void GetFriendGroup()
        {
            //var temp = new ObservableCollection<FriendGroup> { 
            //    new FriendGroup {
            //        GroupName="我的好友",
            //        Friends= new ObservableCollection<User>  {
            //            new User{Id=10001, Username="张三", Signature="牛逼死了1" },
            //            new User{Id=10000, Username="李四", Signature="牛逼死了1" },
            //        }
            //    },
            //    new FriendGroup {
            //        GroupName="逗比们",
            //        Friends= new ObservableCollection<User>  {
            //            new User{Id=10001, Username="张三", Signature="牛逼死了1" },
            //            new User{Id=10000, Username="李四", Signature="牛逼死了1" },
            //        }
            //    },
            //    new FriendGroup {
            //        GroupName="罗莉们",
            //        Friends= new ObservableCollection<User>  {
            //            new User{Id=10001, Username="张三", Signature="牛逼死了1" },
            //            new User{Id=10000, Username="李四", Signature="牛逼死了1" },
            //        }
            //    },
            //    new FriendGroup {
            //        GroupName="御姐们",
            //        Friends= new ObservableCollection<User>  {
            //            new User{Id=10001, Username="张三", Signature="牛逼死了1" },
            //            new User{Id=10000, Username="李四", Signature="牛逼死了1" },
            //        }
            //    }
            //};

            var temp = new ObservableCollection<FriendGroup>(User.Storages
                 .GroupBy(u => u.GroupName)
                 .Select(g => new FriendGroup
                 {
                     GroupName = g.Key,
                     Friends = new ObservableCollection<User>(g.AsEnumerable())
                 }));

            Clients.Caller.GetFriendGroupCallback(temp);
        }
    }
}